/*
  利用forward进行函数调用传参
  利用forward和move进行完美转发
*/

#include <utility>
#include <iostream>
#include <memory>
#include <string>

class Myclass
{
public:
  Myclass(int x, std::string buffer)
  {
    _x = x;
    _s = buffer;
    std::cout << "_x: " << _x << " ";
    std::cout << "_s: " << _s << std::endl;
  }

private:
  int _x;
  std::string _s;
};

template <typename T, typename... Args>
static std::shared_ptr<T> create(Args... args)
{
  return std::make_shared<T>(std::forward<Args>(args)...); // Args就是参数包，等到调用的时候自动展开
}

void process(int &x)
{
  std::cout << "void process(int& x)" << std::endl;
}

void process(int &&x)
{
  std::cout << "void process(int&& x)" << std::endl;
}

template<typename T>
void forwarder(T&& arg)
{
    return process(std::forward<T>(arg));
}

int main()
{
  std::string buffer = {"123456"};
  std::shared_ptr<Myclass> ptr = create<Myclass>(5, buffer);

  forwarder(20);
  int c = 10;
  forwarder(c);

  return 0;
}